package com.example.testapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

import com.example.testapplication.view.MyImageView;

/**
 * 测试MotionEvent的界面
 * 屏幕触控机制(MotionEvent)
 * 事件发生的顺序:
 *   down--->move-->move-->move-->....-->up
 *
 */
public class MotionEventTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_motion_event_test);

        // 得到MYimageView
        MyImageView iv_touch_test = (MyImageView) findViewById(R.id.iv_touch_test);

        // 设置touch 监听
        iv_touch_test.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                Log.e("TAG","MyImageView listenter onTouch() " + motionEvent.getAction());

                if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
                    return true;
                }
                return false;
            }
        });


    }
    // 分发事件
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

        Log.i("TAG", "Activity dispatchTouchEvent() "+ev.getAction());
        return super.dispatchTouchEvent(ev);
    }
    // 处理事件回调
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.i("TAG", "Activity onTouchEvent() "+event.getAction());
        return super.onTouchEvent(event);
    }
}